<?php

namespace App\Models\Entity\Column;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ColumnFun
 * @package App\Models\Entity\Column
 * @version June 26, 2018, 5:26 pm CST
 *
 * @property \App\Models\Entity\Column\Sp sp
 * @property \App\Models\Entity\Column\Ogroup ogroup
 * @property string name
 * @property string title
 * @property integer sp_id
 * @property integer ogroup_id
 * @property string onclick
 * @property string restful
 * @property string description
 */
class ColumnFun extends Model
{
    use SoftDeletes;

    public $table = 'column_funs';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'title',
        'sp_id',
        'ogroup_id',
        'onclick',
        'restful',
        'description',
        // icon值
        'img',
        // icon类型
        'icon_type',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'        => 'string',
        'title'       => 'string',
        'sp_id'       => 'integer',
        'ogroup_id'   => 'integer',
        'onclick'     => 'string',
        'restful'     => 'string',
        'description' => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name' => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function sp()
    {
        return $this->hasOne(\App\Models\Common\EntityData\Channel\Sp::class, 'id', 'sp_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function ogroup()
    {
        return $this->hasOne(\App\Models\Common\EntityData\Channel\Ogroup::class, 'id', 'ogroup_id');
    }
}
